/***
  #### Part 2 - SAS** `2_6_Joint_Venture_Data(SAS).sas` 
  **Language**
  **Description** Middle part of the code - Run the SAS code embedded as comment in the Stata file):**
    - **Inputs:** SCnetwork2, JV_cleaned_short
    - **Outputs:** SC_alliances.sas7bdat
  #### Part 3 - Stata** `2_6_Joint_Venture_Data.do`
  **Description:** Final part of the code that calculates the final dataset to be used in the main sample
    - **Inputs:** SC_alliances.sas7bdat
    - **Outputs:** SC_alliances_collapsed

***/

***************************************************************************************************
*** To run this, you first run the Stata file: 2_Joint_Venture_Data.do

*** Combine the Supply Chain Network with the joint venture data ;
%let dir = your_path;
libname mylib "&dir";

proc import datafile= "&dir./SCnetwork2.csv"
     out= SCnetwork2
     dbms=csv
     replace;
     getnames=yes;
run;
proc import datafile= "&dir./JV_cleaned_short.dta"
     out= JV_cleaned_short
     dbms=DTA
     replace;
run;
* Combine the two networks; 
	 proc sql;
	    create table SC_alliances as
	    select distinct a.*, max(b.alliance) as alliance 
	    from SCnetwork2 as a 
	    	left join JV_cleaned_short as b on a.gvkey1=b.gvkey1 and a.gvkey2=b.gvkey2 and b.year between a.fyear-1 and a.fyear+1
	    group by a.gvkey1, a.fyear, a.gvkey2
	    order by a.gvkey1, a.fyear, a.gvkey2
		;
	quit; 
	proc export data = SC_alliances
				file = "&dir./SC_alliances.dta"
				dbms = STATA REPLACE;
	run;

	proc sql; 
	select sum(alliance) as alliances 
	from SC_blocks; 
	quit;
***************************************************************************************************/


